class Trie:

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.dic = {}
        self.word = 'self'

    def insert(self, word: str) -> None:
        """
        Inserts a word into the print(re)
        """
        tmp = self.dic
        for i in word:
            if i in tmp:
                tmp = tmp[i]
            else:
                tmp[i] = {}
                tmp = tmp[i]
        tmp[self.word] = True

    def search(self, word: str) -> bool:
        """
        Returns if the word is in the print(re)
        """
        tmp = self.dic
        for i in word:
            if i in tmp:
                tmp = tmp[i]
            else:
                return False
        return self.word in tmp

    def startsWith(self, prefix: str) -> bool:
        """
        Returns if there is any word in the trie that starts with the given prefix.
        """
        tmp = self.dic
        for i in prefix:
            if i in tmp:
                tmp = tmp[i]
            else:
                return False
        return True


if __name__ == '__main__':
    # Your Trie object will be instantiated and called as such:
    trie = Trie()

    re = trie.insert("apple");
    print(re)
    re = trie.search("apple");  # 返回
    # true
    print(re)
    re = trie.search("app");  # 返回
    # false
    print(re)
    re = trie.startsWith("app");  # 返回
    # true
    print(re)
    re = trie.insert("app");
    print(re)
    re = trie.search("app");  # 返回
    # true
    print(re)
